<template>
  <div class="werapp">
    <van-nav-bar title="我的收藏" left-arrow @click-left="$router.go(-1)">
    </van-nav-bar>
    <Loading v-if="list == ''" />
    <div class="q1" v-else>
      <div class="heard-item" v-for="item in list.list" :key="item.collect_id">
        <div class="h1">
          <h1>{{ item.title }}</h1>
          <van-icon
            name="star-o"
            size="20"
            @click="status(item)"
            class="color"
          />
        </div>
        <p>共{{ item.section_num }}课时</p>
        <div class="box-item">
          <img :src="item.teachersAvatar" alt="" />
          <span>{{ item.teachers }}</span>
        </div>
        <div class="info">
          <p class="books">{{ item.sales_num }}人已报名</p>
          <h1 class="color">
            <span class="icon iconfont">&#xe620;</span>{{ item.price }}
          </h1>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Loading from "../commponts/loading.vue";
import { collects1, collectss, courseInfo } from "../../request/http";
export default {
  components: {
    Loading,
  },
  data() {
    return {
      list: [],
      arr: [],
      pams: {
        page: 1,
        limit: 10,
        type: 1,
      },
    };
  },
  methods: {
    status(v) {
      console.log(v);
      collectss({ collect_id: v.collect_id, type: 1 }).then((res) => {
        console.log(res);
        this.arr.info.is_collect = 0;
        Toast.success("取消收藏");
      });

      collects1(this.pams).then((res) => {
        console.log(res);
        this.list = res.data;
      });
    },
  },
  created() {
    courseInfo(this.$route.query.id).then((res) => {
      console.log(res);
      this.arr = res.data;
    });
    collects1(this.pams).then((res) => {
      console.log(res);
      this.list = res.data;
    });
  },
};
</script>

<style lang="scss" scoped>
.werapp {
  background: rgb(242, 243, 245);
}
.q1 {
  padding: 0.4rem 0.267rem;
}
.heard-item {
  padding: 0 40px;
  border: 1px solid #fff;
  background: #fff;
  margin-bottom: 20px;
  .box-item {
    img {
      width: 0.96rem;
      height: 0.96rem;
      border-radius: 50%;
      vertical-align: middle;
      border: 1px solid black;
    }
    span {
      font-size: 0.4rem;
      color: rgba(0, 0, 0, 0.45);
      vertical-align: middle;
      margin-left: 0.4rem;
      display: inline-block;
      width: 3.2rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .h1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .color {
    color: orange;
  }
  .info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .books {
      font-size: 0.427rem;
      color: #777;
      margin: 0;
    }
  }
}
</style>